using System.Collections.ObjectModel;
using HMCollada.Core;
using System.Xml;
using HMCollada.FX;

namespace HMCollada.FX {
    internal struct HMColladaTechnique {
        internal string id;
        internal string sid;
        internal HMColladaAsset asset;
        internal HMColladaLighting lighting;
        internal Collection<HMColladaNewParam> newparam;
        internal Collection<HMColladaSetParam> setparam;
    }
}

namespace HMCollada {
    internal partial class HMColladaLoader {
        private static HMColladaTechnique LoadTechnique() {
            HMColladaTechnique newTechnique = new HMColladaTechnique();
            newTechnique.id = colladaReader.GetAttribute("id");
            newTechnique.sid = colladaReader.GetAttribute("sid");

            newTechnique.newparam = new Collection<HMColladaNewParam>();
            newTechnique.setparam = new Collection<HMColladaSetParam>();

            if (!colladaReader.IsEmptyElement) colladaReader.Read();
            do {
                if (colladaReader.NodeType != XmlNodeType.EndElement) {
                    switch (colladaReader.Name) {
                        case "asset": newTechnique.asset = LoadAsset(); break;
                        case "constant": newTechnique.lighting = new HMColladaConstant(); break;
                        case "lambert": newTechnique.lighting = new HMColladaLambert(); break;
                        case "phong": newTechnique.lighting = new HMColladaPhong(); break;
                        case "blinn": newTechnique.lighting = new HMColladaBlinn(); break;

                        case "emission": newTechnique.lighting.Emission = ReadColor(); break;
                        case "ambient": newTechnique.lighting.Ambient = ReadColor(); break;
                        case "diffuse": newTechnique.lighting.Diffuse = ReadColor(); break;
                        case "specular": newTechnique.lighting.Specular = ReadColor(); break;
                        case "shininess": newTechnique.lighting.Shininess = ReadFloat(); break;
                        case "reflective": newTechnique.lighting.Reflective = ReadColor(); break;
                        case "reflectivity": newTechnique.lighting.Reflectivity = ReadFloat(); break;
                        case "transparent": newTechnique.lighting.Transparent = ReadColor(); break;
                        case "transparency": newTechnique.lighting.Transparency = ReadFloat(); break;
                        case "index_of_refraction": newTechnique.lighting.IndexOfRefraction = ReadFloat(); break;

                        case "newparam": newTechnique.newparam.Add(LoadNewParam()); break;
                        case "setparam": newTechnique.setparam.Add(LoadSetParam()); break;
                    }
                }

                if (!colladaReader.IsEmptyElement) colladaReader.Read();
            } while (colladaReader.Name != "technique");

            if (colladaReader.IsEmptyElement) colladaReader.Read();
            return newTechnique;
        }
    }
}